package com.xdw.permissionslib.mylibrary;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;

/**
 * LazyPermissionAblity
 * lazy权限模式，将需要权限控制的Ability继承该类
 * 然后在子类的onStart方法的第一行调用setPermissions传入需要申请的权限组即可完成权限所有操作。
 */
public class LazyPermissionAblity extends Ability {
    private String[] permissions;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        LazyPermissionsUtils.getInstance(this).checkPermissions(this,permissions);
    }

    @Override
    public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsFromUserResult(requestCode, permissions, grantResults);
        LazyPermissionsUtils.getInstance(this).onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    public void setPermissions(String[] permissions) {
        this.permissions = permissions;
    }
}
